window._ROF = {

    //根据游戏难度修正敌人数值
    recreateObjByHdlv:function(tmpobj){

        if(_HDLVHELPER.getHdLv()==0){
            return;
        }

        //if(!tmpobj.isboss){
        //   tmpobj.cha = _CU.randomObj(_CHARACTERHELPER.getAllCha());
        //}

        var hlvAdd = _HDLVHELPER.getAttrByHdLv('hlvAdd');
        var attrAdd = _HDLVHELPER.getAttrByHdLv('attrAdd');
        var equipQua = _HDLVHELPER.getAttrByHdLv('equipQua');

        if(_JOB[tmpobj.job]&&_JOB[tmpobj.job].equipType&&_JOB[tmpobj.job].equipType.length>0){

            if(!tmpobj.lv){
                tmpobj.lv = _EXPMANAGER.getLevelByExp(tmpobj.exp);
            }

            var recreateEquipObj = _EQUIPHELPER.getEuipObj(tmpobj.job,tmpobj.lv,equipQua,null);
            //console.log('重新构造装备',recreateEquipObj,tmpobj.job,tmpobj.lv,equipQua);
            tmpobj.equip = recreateEquipObj;
        }
        _EQUIPMODELHELPER.initRoleEquipByModel(tmpobj);
        if(tmpobj.isboss){
            tmpobj.hlv+=hlvAdd;
        }else{
            tmpobj.hlv=Math.floor(tmpobj.hlv*attrAdd);
        }

        _ROF.calAttrAdd(tmpobj,attrAdd);

        var npcdata = _ROLEDATA.getRoleDataOfPlayer(tmpobj);
        tmpobj.hp = npcdata.maxHp;
        tmpobj.mg = npcdata.maxMagic;
    },

    calAttrAdd:function(tmpobj,attrAdd){
        var tmparr = [
                      {attr:'plv',value:tmpobj.plv},
                      {attr:'ilv',value:tmpobj.ilv},
                      {attr:'mlv',value:tmpobj.mlv},
                      {attr:'dlv',value:tmpobj.dlv}];

        //tmpobj.plv=Math.floor(tmpobj.plv*attrAdd);
        //tmpobj.ilv=Math.floor(tmpobj.ilv*attrAdd);
        //tmpobj.mlv=Math.floor(tmpobj.mlv*attrAdd);
        //tmpobj.dlv=Math.floor(tmpobj.dlv*attrAdd);
        tmparr.sort((a,b)=>{
            return b.value-a.value;
        });

        for(var i=0;i<2;i++){
            tmpobj[tmparr[i].attr]=Math.floor(tmpobj[tmparr[i].attr]*attrAdd);
        }
    },

    createAnimal:function(roleName,lv,param){
        var tmpobj = _CU.cloneObj(_NPC[roleName]);
        if(param&&param.isboss){
            tmpobj.isboss = true;
        }
        if(param&&param.ftype){
            tmpobj.ftype = param.ftype;
        }
        if(param&&param.attr){
            //tmpobj.plv=param.attr;
            tmpobj.dlv=param.attr;
            //tmpobj.ilv=param.attr;
            tmpobj.mlv=param.attr;
            tmpobj.hlv=param.attr;
        }
        tmpobj.exp = _EXPMANAGER.getExpByLevel(lv);
        var npcdata = _ROLEDATA.getRoleDataOfPlayer(tmpobj);
        tmpobj.hp = npcdata.maxHp;
        tmpobj.mg = npcdata.maxMagic;
        if(!tmpobj.skill){
            tmpobj.skill=[];
        }
        return tmpobj;
    },


    getEquipQuaByLv:function(lv){
        var mlv = lv%100;
        if(mlv==0){
            return 'SS';
        }else if(mlv>90){
            return 'S';
        }else if(mlv>60){
            return 'A';
        }else if(mlv>30){
            return 'B';
        }else {
            return 'C';
        }
    },

    
    createRoleAndSetPlayerLv(roleName){

        var cityFightLv = _HDLVHELPER.getAttrByHdLv('cityFightLv');
        var playerLv = _GAMEDATAHELPER.getTeamLv();
        var tmpobj = _CU.cloneObj(_NPC[roleName]);
        var realLv = tmpobj.lv>(playerLv+cityFightLv)?tmpobj.lv:(playerLv+cityFightLv);
        if(realLv>1000){
            realLv=1000;
        }
        tmpobj.isboss = true;
        tmpobj.exp = _EXPMANAGER.getExpByLevel(realLv);
        var qua = tmpobj.qua;
        if(_JOB[tmpobj.job]&&_JOB[tmpobj.job].equipType&&_JOB[tmpobj.job].equipType.length>0)
            tmpobj.equip = _EQUIPHELPER.getEuipObj(tmpobj.job,tmpobj.lv,qua,null);
        _EQUIPMODELHELPER.initRoleEquipByModel(tmpobj);
        var npcdata = _ROLEDATA.getRoleDataOfPlayer(tmpobj);
        tmpobj.hp = npcdata.maxHp;
        tmpobj.mg = npcdata.maxMagic;
        if(!tmpobj.skill){
            tmpobj.skill=[];
        }
        return tmpobj;

    },


    createRole:function(roleName){
        var tmpobj = _CU.cloneObj(_NPC[roleName]);
        tmpobj.isboss = true;
        tmpobj.exp = _EXPMANAGER.getExpByLevel(tmpobj.lv);
        var qua = tmpobj.qua;
        if(_JOB[tmpobj.job]&&_JOB[tmpobj.job].equipType&&_JOB[tmpobj.job].equipType.length>0)
            tmpobj.equip = _EQUIPHELPER.getEuipObj(tmpobj.job,tmpobj.lv,qua,null);
        _EQUIPMODELHELPER.initRoleEquipByModel(tmpobj);
        var npcdata = _ROLEDATA.getRoleDataOfPlayer(tmpobj);
        tmpobj.hp = npcdata.maxHp;
        tmpobj.mg = npcdata.maxMagic;
        if(!tmpobj.skill){
            tmpobj.skill=[];
        }
        return tmpobj;
    },


    createJobRole:function(jobName,param){
        var jobConfig = _JOB[jobName]
        if(jobConfig&&param){
            var flag = param.flag;
            var lv = param.lv;
            var equiplv = param.equiplv;
            var attr = param.attr;
            var ftype = param.ftype;
            var npcname = param.npcname;
            var face = flag?jobConfig.face:jobConfig.face.replace('官','贼');
            var pf = flag?jobConfig.pf:jobConfig.pf.replace('官','贼');
            var randomSkill = _SKILLHEPLER.getRandomSkillForJob(jobName,ftype);
            var skillArr = randomSkill?[randomSkill]:[];

            var tmpnpc = {name:npcname,face:face,pf:pf,ftype:ftype,job:jobName,
                plv:attr,dlv:attr,ilv:attr,mlv:attr,hlv:attr,sex:0,skill:skillArr,equip:null};
            var equipObj = _EQUIPHELPER.getEuipObj(tmpnpc.job,lv,equiplv,null);
            tmpnpc.equip = equipObj;
            //tmpnpc.equip =JSON.parse(JSON.stringify(equipObj));
            //console.log(equipObj,tmpnpc.equip,tmpnpc,JSON.stringify(tmpnpc));
            tmpnpc.exp = _EXPMANAGER.getExpByLevel(lv);

            var npcdata = _ROLEDATA.getRoleDataOfPlayer(tmpnpc);
            tmpnpc.hp = npcdata.maxHp;
            tmpnpc.mg = npcdata.maxMagic;
            //console.log('构造小兵',tmpnpc);
            return tmpnpc;
        }
        return null;
    }


}